<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1">
  <title id="cd20941">CREATE TABLE</title>
  <body>
    <p id="sql_command_desc">Defines a new table.</p>
    <note type="note">Referential integrity syntax (foreign key constraints) is accepted but not
      enforced.</note>
    <section id="section2">
      <title>Synopsis</title>
      <codeblock id="sql_command_synopsis">
CREATE [ [GLOBAL | LOCAL] {TEMPORARY | TEMP } | UNLOGGED] TABLE [IF NOT EXISTS] 
  <varname>table_name</varname> ( 
  [ { <varname>column_name</varname> <varname>data_type</varname> [ COLLATE <varname>collation</varname> ] [<varname>column_constraint</varname> [ ... ] ]
[ ENCODING ( <varname>storage_directive</varname> [, ...] ) ]
    | <varname>table_constraint</varname>
    | LIKE <varname>source_table</varname> [ <varname>like_option</varname> ... ] }
    | [ <varname>column_reference_storage_directive</varname> [, ...]
    [, ... ]
] )
[ INHERITS ( <varname>parent_table</varname> [, ... ] ) ]
[ WITH ( <varname>storage_parameter</varname> [=<varname>value</varname>] [, ... ] ) ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE <varname>tablespace_name</varname> ]
[ DISTRIBUTED BY (<varname>column</varname> [<varname>opclass</varname>], [ ... ] ) 
       | DISTRIBUTED RANDOMLY | DISTRIBUTED REPLICATED ]

{ <b>--partitioned table using SUBPARTITION TEMPLATE</b>
[ PARTITION BY <varname>partition_type</varname> (<varname>column</varname>) 
  {  [ SUBPARTITION BY <varname>partition_type</varname> (<varname>column1</varname>) 
       SUBPARTITION TEMPLATE ( <varname>template_spec</varname> ) ]
          [ SUBPARTITION BY partition_type (<varname>column2</varname>) 
            SUBPARTITION TEMPLATE ( <varname>template_spec</varname> ) ]
              [...]  }
  ( <varname>partition_spec</varname> ) ]
} |

{ <b>-- partitioned table without SUBPARTITION TEMPLATE
</b>[ PARTITION BY <varname>partition_type</varname> (<varname>column</varname>)
   [ SUBPARTITION BY <varname>partition_type</varname> (<varname>column1</varname>) ]
      [ SUBPARTITION BY <varname>partition_type</varname> (<varname>column2</varname>) ]
         [...]
  ( <varname>partition_spec</varname>
     [ ( <varname>subpartition_spec_column1</varname>
          [ ( <varname>subpartition_spec_column2</varname>
               [...] ) ] ) ],
  [ <varname>partition_spec</varname>
     [ ( <varname>subpartition_spec_column1</varname>
        [ ( <varname>subpartition_spec_column2</varname>
             [...] ) ] ) ], ]
    [...]
  ) ]
}

CREATE [ [GLOBAL | LOCAL] {TEMPORARY | TEMP} | UNLOGGED ] TABLE [IF NOT EXISTS] 
   <varname>table_name</varname>
    OF <varname>type_name</varname> [ (
  { <varname>column_name</varname> WITH OPTIONS [ <varname>column_constraint</varname> [ ... ] ]
    | <varname>table_constraint</varname> } 
    [, ... ]
) ]
[ WITH ( <varname>storage_parameter</varname> [=<varname>value</varname>] [, ... ] ) ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE <varname>tablespace_name</varname> ]
</codeblock>
      <p>where <varname>column_constraint</varname> is:</p>
      <codeblock>[ CONSTRAINT <varname>constraint_name</varname>]
{ NOT NULL 
  | NULL 
  | CHECK  ( <varname>expression</varname> ) [ NO INHERIT ]
  | DEFAULT <varname>default_expr</varname>
  | UNIQUE <varname>index_parameters</varname>
  | PRIMARY KEY <varname>index_parameters</varname>
  | REFERENCES <varname>reftable</varname> [ ( refcolumn ) ] 
      [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]  
      [ ON DELETE <varname>key_action</varname> ] [ ON UPDATE <varname>key_action</varname> ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]</codeblock>
      <p>and <varname>table_constraint</varname> is:</p>
      <codeblock>[ CONSTRAINT <varname>constraint_name</varname> ]
{ CHECK ( <varname>expression</varname> ) [ NO INHERIT ]
  | UNIQUE ( <varname>column_name</varname> [, ... ] ) <varname>index_parameters</varname>
  | PRIMARY KEY ( <varname>column_name</varname> [, ... ] ) <varname>index_parameters</varname>
  | FOREIGN KEY ( <varname>column_name</varname> [, ... ] ) 
      REFERENCES <varname>reftable</varname> [ ( <varname>refcolumn</varname> [, ... ] ) ]
      [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] 
      [ ON DELETE <varname>key_action</varname> ] [ ON UPDATE <varname>key_action</varname> ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]</codeblock>
      <p>and <i>like_option</i>
        is:<codeblock>{INCLUDING|EXCLUDING} {DEFAULTS|CONSTRAINTS|INDEXES|STORAGE|COMMENTS|ALL}</codeblock></p>
      <p>and <varname>index_parameters</varname> in <codeph>UNIQUE</codeph> and <codeph>PRIMARY
          KEY</codeph> constraints are:</p>
      <codeblock>[ WITH ( <varname>storage_parameter</varname> [=<varname>value</varname>] [, ... ] ) ]
[ USING INDEX TABLESPACE <varname>tablespace_name</varname> ] </codeblock>
      <p>and <varname>storage_directive</varname> for a column is:</p>
      <codeblock>   compresstype={ZLIB|ZSTD|QUICKLZ|RLE_TYPE|NONE}
    [compresslevel={0-9}]
    [blocksize={8192-2097152} ]</codeblock>
      <p>and <varname>storage_parameter</varname> for the table is:</p>
      <codeblock>   appendoptimized={TRUE|FALSE}
   blocksize={8192-2097152}
   orientation={COLUMN|ROW}
   checksum={TRUE|FALSE}
   compresstype={ZLIB|ZSTD|QUICKLZ|RLE_TYPE|NONE}
   compresslevel={0-9}
   fillfactor={10-100}
   [oids=FALSE]</codeblock>
      <p>and <varname>key_action</varname> is:</p>
      <codeblock>    ON DELETE 
  | ON UPDATE
  | NO ACTION
  | RESTRICT
  | CASCADE
  | SET NULL
  | SET DEFAULT</codeblock>
      <p>and <varname>partition_type</varname> is:</p>
      <codeblock>    LIST | RANGE</codeblock>
      <p>and <varname>partition_specification</varname> is:</p>
      <codeblock><varname>partition_element</varname> [, ...]</codeblock>
      <p>and <varname>partition_element</varname> is:</p>
      <codeblock>   DEFAULT PARTITION <varname>name</varname>
  | [PARTITION <varname>name</varname>] VALUES (<varname>list_value</varname> [,...] )
  | [PARTITION <varname>name</varname>] 
     START ([<varname>datatype</varname>] '<varname>start_value</varname>') [INCLUSIVE | EXCLUSIVE]
     [ END ([<varname>datatype</varname>] '<varname>end_value</varname>') [INCLUSIVE | EXCLUSIVE] ]
     [ EVERY ([<varname>datatype</varname>] [<varname>number | </varname>INTERVAL] '<varname>interval_value</varname>') ]
  | [PARTITION <varname>name</varname>] 
     END ([<varname>datatype</varname>] '<varname>end_value</varname>') [INCLUSIVE | EXCLUSIVE]
     [ EVERY ([<varname>datatype</varname>] [<varname>number | </varname>INTERVAL] '<varname>interval_value</varname>') ]
[ WITH ( <varname>partition_storage_parameter</varname>=<varname>value</varname> [, ... ] ) ]
[ <varname>column_reference_storage_directive</varname> [, ...] ]
[ TABLESPACE <varname>tablespace</varname> ]</codeblock>
      <p>where <varname>subpartition_spec</varname> or <varname>template_spec</varname> is:</p>
      <codeblock><varname>subpartition_element</varname> [, ...]</codeblock>
      <p>and <varname>subpartition_element</varname> is:</p>
      <codeblock>   DEFAULT SUBPARTITION <varname>name</varname>
  | [SUBPARTITION <varname>name</varname>] VALUES (<varname>list_value</varname> [,...] )
  | [SUBPARTITION <varname>name</varname>] 
     START ([<varname>datatype</varname>] '<varname>start_value</varname>') [INCLUSIVE | EXCLUSIVE]
     [ END ([<varname>datatype</varname>] '<varname>end_value</varname>') [INCLUSIVE | EXCLUSIVE] ]
     [ EVERY ([<varname>datatype</varname>] [<varname>number | </varname>INTERVAL] '<varname>interval_value</varname>') ]
  | [SUBPARTITION <varname>name</varname>] 
     END ([<varname>datatype</varname>] '<varname>end_value</varname>') [INCLUSIVE | EXCLUSIVE]
     [ EVERY ([<varname>datatype</varname>] [<varname>number | </varname>INTERVAL] '<varname>interval_value</varname>') ]
[ WITH ( <varname>partition_storage_parameter</varname>=<varname>value</varname> [, ... ] ) ]
[ <varname>column_reference_storage_directive</varname> [, ...] ]
[ TABLESPACE <varname>tablespace</varname> ]</codeblock>
      <p>where <varname>storage_parameter</varname> for a partition is:</p>
      <codeblock>   appendoptimized={TRUE|FALSE}
   blocksize={8192-2097152}
   orientation={COLUMN|ROW}
   checksum={TRUE|FALSE}
   compresstype={ZLIB|ZSTD|QUICKLZ|RLE_TYPE|NONE}
   compresslevel={1-19}
   fillfactor={10-100}
   [oids=FALSE]</codeblock>
    </section>
    <section id="section3">
      <title>Description</title>
      <p><codeph>CREATE TABLE</codeph> creates an initially empty table in the current database. The
        user who issues the command owns the table.</p>
      <p>To be able to create a table, you must have <codeph>USAGE</codeph> privilege on all column
        types or the type in the <codeph>OF</codeph> clause, respectively. </p>
      <p>If you specify a schema name, Greenplum creates the table in the specified schema.
        Otherwise Greenplum creates the table in the current schema. Temporary tables exist in a
        special schema, so you cannot specify a schema name when creating a temporary table. Table
        names must be distinct from the name of any other table, external table, sequence, index,
        view, or foreign table in the same schema.</p>
      <p><codeph>CREATE TABLE</codeph> also automatically creates a data type that represents the
        composite type corresponding to one row of the table. Therefore, tables cannot have the same
        name as any existing data type in the same schema.</p>
      <p>The optional constraint clauses specify conditions that new or updated rows must satisfy
        for an insert or update operation to succeed. A constraint is an SQL object that helps
        define the set of valid values in the table in various ways. Constraints apply to tables,
        not to partitions. You cannot add a constraint to a partition or subpartition.</p>
      <p>Referential integrity constraints (foreign keys) are accepted but not enforced. The
        information is kept in the system catalogs but is otherwise ignored.</p>
      <p>There are two ways to define constraints: table constraints and column constraints. A
        column constraint is defined as part of a column definition. A table constraint definition
        is not tied to a particular column, and it can encompass more than one column. Every column
        constraint can also be written as a table constraint; a column constraint is only a
        notational convenience for use when the constraint only affects one column. </p>
      <p>When creating a table, there is an additional clause to declare the Greenplum Database
        distribution policy. If a <codeph>DISTRIBUTED BY</codeph>, <codeph>DISTRIBUTED
          RANDOMLY</codeph>, or <codeph>DISTRIBUTED REPLICATED</codeph> clause is not supplied, then
        Greenplum Database assigns a hash distribution policy to the table using either the
          <codeph>PRIMARY KEY</codeph> (if the table has one) or the first column of the table as
        the distribution key. Columns of geometric or user-defined data types are not eligible as
        Greenplum distribution key columns. If a table does not have a column of an eligible data
        type, the rows are distributed based on a round-robin or random distribution. To ensure an
        even distribution of data in your Greenplum Database system, you want to choose a
        distribution key that is unique for each record, or if that is not possible, then choose
          <codeph>DISTRIBUTED RANDOMLY</codeph>. </p>
      <p>If the <codeph>DISTRIBUTED REPLICATED</codeph> clause is supplied, Greenplum Database
        distributes all rows of the table to all segments in the Greenplum Database system. This
        option can be used in cases where user-defined functions must run on the segments, and
        the functions require access to all rows of the table. Replicated functions can also be used
        to improve query performance by preventing broadcast motions for the table. The
          <codeph>DISTRIBUTED REPLICATED</codeph> clause cannot be used with the <codeph>PARTITION
          BY</codeph> clause or the <codeph>INHERITS</codeph> clause. A replicated table also cannot
        be inherited by another table. The hidden system columns (<codeph>ctid</codeph>,
          <codeph>cmin</codeph>, <codeph>cmax</codeph>, <codeph>xmin</codeph>,
        <codeph>xmax</codeph>, and <codeph>gp_segment_id</codeph>) cannot be referenced in user
        queries on replicated tables because they have no single, unambiguous value. Greenplum
        Database returns a <codeph>column does not exist</codeph> error for the query.</p>
      <p>The <codeph>PARTITION BY</codeph> clause allows you to divide the table into multiple
        sub-tables (or parts) that, taken together, make up the parent table and share its schema.
        Though the sub-tables exist as independent tables, the Greenplum Database restricts their
        use in important ways. Internally, partitioning is implemented as a special form of
        inheritance. Each child table partition is created with a distinct <codeph>CHECK</codeph>
        constraint which limits the data the table can contain, based on some defining criteria. The
          <codeph>CHECK</codeph> constraints are also used by the query optimizer to determine which
        table partitions to scan in order to satisfy a given query predicate. These partition
        constraints are managed automatically by the Greenplum Database.</p>
    </section>
    <section id="section4">
      <title>Parameters</title>
      <parml>
        <plentry>
          <pt>GLOBAL | LOCAL</pt>
          <pd>These keywords are present for SQL standard compatibility, but have no effect in
            Greenplum Database and are deprecated.</pd>
        </plentry>
        <plentry>
          <pt>TEMPORARY | TEMP</pt>
          <pd>If specified, the table is created as a temporary table. Temporary tables are
            automatically dropped at the end of a session, or optionally at the end of the current
            transaction (see <codeph>ON COMMIT</codeph>). Existing permanent tables with the same
            name are not visible to the current session while the temporary table exists, unless
            they are referenced with schema-qualified names. Any indexes created on a temporary
            table are automatically temporary as well.</pd>
        </plentry>
        <plentry>
          <pt>UNLOGGED</pt>
          <pd>If specified, the table is created as an unlogged table. Data written to unlogged
            tables is not written to the write-ahead (WAL) log, which makes them considerably faster
            than ordinary tables. However, the contents of an unlogged table are not replicated to
            mirror segment instances. Also an unlogged table is not crash-safe. After a segment
            instance crash or unclean shutdown, the data for the unlogged table on that segment is
            truncated. Any indexes created on an unlogged table are automatically unlogged as
            well.</pd>
        </plentry>
        <plentry>
          <pt>
            <varname>table_name</varname>
          </pt>
          <pd>The name (optionally schema-qualified) of the table to be created. </pd>
        </plentry>
        <plentry>
          <pt>OF <varname>type_name</varname></pt>
          <pd>Creates a typed table, which takes its structure from the specified composite type
            (name optionally schema-qualified). A typed table is tied to its type; for example the
            table will be dropped if the type is dropped (with <codeph>DROP TYPE ...
              CASCADE</codeph>).</pd>
          <pd> When a typed table is created, the data types of the columns are determined by the
            underlying composite type and are not specified by the <codeph>CREATE TABLE</codeph>
            command. But the <codeph>CREATE TABLE</codeph> command can add defaults and constraints
            to the table and can specify storage parameters. </pd>
        </plentry>
        <plentry>
          <pt>
            <varname>column_name</varname>
          </pt>
          <pd>The name of a column to be created in the new table. </pd>
        </plentry>
        <plentry>
          <pt>
            <varname>data_type</varname>
          </pt>
          <pd>The data type of the column. This may include array specifiers.</pd>
          <pd>For table columns that contain textual data, Specify the data type
              <codeph>VARCHAR</codeph> or <codeph>TEXT</codeph>. Specifying the data type
              <codeph>CHAR</codeph> is not recommended. In Greenplum Database, the data types
              <codeph>VARCHAR</codeph> or <codeph>TEXT</codeph> handles padding added to the data
            (space characters added after the last non-space character) as significant characters,
            the data type <codeph>CHAR</codeph> does not. See <xref href="#topic1/section5"
              format="dita"/>.</pd>
        </plentry>
        <plentry>
          <pt>COLLATE <varname>collation</varname></pt>
          <pd>The <codeph>COLLATE</codeph> clause assigns a collation to the column (which must be
            of a collatable data type). If not specified, the column data type's default collation
            is used.<note>GPORCA supports collation only when all columns in the query use the same
              collation. If columns in the query use different collations, then Greenplum uses the
              Postgres Planner.</note></pd>
        </plentry>
        <plentry>
          <pt>DEFAULT <varname>default_expr</varname></pt>
          <pd>The <codeph>DEFAULT</codeph> clause assigns a default data value for the column whose
            column definition it appears within. The value is any variable-free expression
            (subqueries and cross-references to other columns in the current table are not allowed).
            The data type of the default expression must match the data type of the column. The
            default expression will be used in any insert operation that does not specify a value
            for the column. If there is no default for a column, then the default is null. </pd>
        </plentry>
        <plentry>
          <pt> ENCODING ( <varname>storage_directive</varname> [, ...] ) </pt>
          <pd>For a column, the optional <codeph>ENCODING</codeph> clause specifies the type of
            compression and block size for the column data. See <xref href="#topic1/with_storage"
              format="dita">storage_options</xref> for <codeph>compresstype</codeph>,
              <codeph>compresslevel</codeph>, and <codeph>blocksize</codeph> values.</pd>
          <pd>The clause is valid only for append-optimized, column-oriented tables.</pd>
          <pd>Column compression settings are inherited from the table level to the partition level
            to the subpartition level. The lowest-level settings have priority.</pd>
        </plentry>
        <plentry>
          <pt>INHERITS ( parent_table [, …])</pt>
          <pd>The optional <codeph>INHERITS</codeph> clause specifies a list of tables from which
            the new table automatically inherits all columns. Use of <codeph>INHERITS</codeph>
            creates a persistent relationship between the new child table and its parent table(s).
            Schema modifications to the parent(s) normally propagate to children as well, and by
            default the data of the child table is included in scans of the parent(s). </pd>
          <pd>In Greenplum Database, the <codeph>INHERITS</codeph> clause is not used when creating
            partitioned tables. Although the concept of inheritance is used in partition
            hierarchies, the inheritance structure of a partitioned table is created using the
                <codeph><xref href="#topic1/part_by" format="dita">PARTITION BY</xref></codeph>
            clause. </pd>
          <pd>If the same column name exists in more than one parent table, an error is reported
            unless the data types of the columns match in each of the parent tables. If there is no
            conflict, then the duplicate columns are merged to form a single column in the new
            table. If the column name list of the new table contains a column name that is also
            inherited, the data type must likewise match the inherited column(s), and the column
            definitions are merged into one. If the new table explicitly specifies a default value
            for the column, this default overrides any defaults from inherited declarations of the
            column. Otherwise, any parents that specify default values for the column must all
            specify the same default, or an error will be reported. </pd>
          <pd><codeph>CHECK</codeph> constraints are merged in essentially the same way as columns:
            if multiple parent tables or the new table definition contain identically-named
              <codeph>constraints</codeph>, these constraints must all have the same check
            expression, or an error will be reported. Constraints having the same name and
            expression will be merged into one copy. A constraint marked <codeph>NO INHERIT</codeph>
            in a parent will not be considered. Notice that an unnamed <codeph>CHECK</codeph>
            constraint in the new table will never be merged, since a unique name will always be
            chosen for it.</pd>
          <pd>Column <codeph>STORAGE</codeph> settings are also copied from parent tables.</pd>
        </plentry>
        <plentry>
          <pt>LIKE <varname>source_table</varname>
            <varname>like_option</varname>
            <codeph>...</codeph>]</pt>
          <pd>The <codeph>LIKE</codeph> clause specifies a table from which the new table
            automatically copies all column names, their data types, not-null constraints, and
            distribution policy. Unlike <codeph>INHERITS</codeph>, the new table and original table
            are completely decoupled after creation is complete.</pd>
          <pd>
            <note>Storage properties like append-optimized or partition structure are not
              copied.</note>
          </pd>
          <pd>Default expressions for the copied column definitions will only be copied if
              <codeph>INCLUDING DEFAULTS</codeph> is specified. The default behavior is to exclude
            default expressions, resulting in the copied columns in the new table having null
            defaults. </pd>
          <pd>Not-null constraints are always copied to the new table. <codeph>CHECK</codeph>
            constraints will be copied only if <codeph>INCLUDING CONSTRAINTS</codeph> is specified.
            No distinction is made between column constraints and table constraints. </pd>
          <pd>Indexes, <codeph>PRIMARY KEY</codeph>, and <codeph>UNIQUE</codeph> constraints on the
            original table will be created on the new table only if the <codeph>INCLUDING
              INDEXES</codeph> clause is specified. Names for the new indexes and constraints are
            chosen according to the default rules, regardless of how the originals were named. (This
            behavior avoids possible duplicate-name failures for the new indexes.)</pd>
          <pd>Any indexes on the original table will not be created on the new table, unless the
              <codeph>INCLUDING INDEXES</codeph> clause is specified.</pd>
          <pd><codeph>STORAGE</codeph> settings for the copied column definitions will be copied
            only if <codeph>INCLUDING STORAGE</codeph> is specified. The default behavior is to
            exclude <codeph>STORAGE</codeph> settings, resulting in the copied columns in the new
            table having type-specific default settings. </pd>
          <pd> Comments for the copied columns, constraints, and indexes will be copied only if
              <codeph>INCLUDING COMMENTS</codeph> is specified. The default behavior is to exclude
            comments, resulting in the copied columns and constraints in the new table having no
            comments. </pd>
          <pd>
            <codeph>INCLUDING ALL</codeph> is an abbreviated form of <codeph>INCLUDING DEFAULTS
              INCLUDING CONSTRAINTS INCLUDING INDEXES INCLUDING STORAGE INCLUDING COMMENTS</codeph>. </pd>
          <pd> Note that unlike <codeph>INHERITS</codeph>, columns and constraints copied by
              <codeph>LIKE</codeph> are not merged with similarly named columns and constraints. If
            the same name is specified explicitly or in another <codeph>LIKE</codeph> clause, an
            error is signaled. </pd>
          <pd>The <codeph>LIKE</codeph> clause can also be used to copy columns from views, foreign
            tables, or composite types. Inapplicable options (e.g., <codeph>INCLUDING
              INDEXES</codeph> from a view) are ignored. </pd>
        </plentry>
        <plentry>
          <pt>CONSTRAINT <varname>constraint_name</varname></pt>
          <pd>An optional name for a column or table constraint. If the constraint is violated, the
            constraint name is present in error messages, so constraint names like <varname>column
              must be positive</varname> can be used to communicate helpful constraint information
            to client applications. (Double-quotes are needed to specify constraint names that
            contain spaces.) If a constraint name is not specified, the system generates a
              name.<note type="note">The specified <varname>constraint_name</varname> is used for
              the constraint, but a system-generated unique name is used for the index name. In some
              prior releases, the provided name was used for both the constraint name and the index
              name. </note></pd>
        </plentry>
        <plentry>
          <pt>NULL | NOT NULL </pt>
          <pd>Specifies if the column is or is not allowed to contain null values.
              <codeph>NULL</codeph> is the default.</pd>
        </plentry>
        <plentry>
          <pt>CHECK (<varname>expression</varname>) [ NO INHERIT ]</pt>
          <pd>The <codeph>CHECK</codeph> clause specifies an expression producing a Boolean result
            which new or updated rows must satisfy for an insert or update operation to succeed.
            Expressions evaluating to <codeph>TRUE</codeph> or <codeph>UNKNOWN</codeph> succeed.
            Should any row of an insert or update operation produce a <codeph>FALSE</codeph> result
            an error exception is raised and the insert or update does not alter the database. A
            check constraint specified as a column constraint should reference that column's value
            only, while an expression appearing in a table constraint can reference multiple
            columns. </pd>
          <pd>A constraint marked with <codeph>NO INHERIT</codeph> will not propagate to child
            tables. </pd>
          <pd> Currently, <codeph>CHECK</codeph> expressions cannot contain subqueries nor refer to
            variables other than columns of the current row. </pd>
        </plentry>
        <plentry>
          <pt>UNIQUE ( <varname>column_constraint</varname> )</pt>
          <pt>UNIQUE ( <varname>column_name</varname> [, ... ] ) (
              <varname>table_constraint</varname> )</pt>
          <pd>The <codeph>UNIQUE</codeph> constraint specifies that a group of one or more columns
            of a table may contain only unique values. The behavior of the unique table constraint
            is the same as that for column constraints, with the additional capability to span
            multiple columns. For the purpose of a unique constraint, null values are not considered
            equal. The column(s) that are unique must contain all the columns of the Greenplum
            distribution key. In addition, the <codeph>&lt;key&gt;</codeph> must contain all the
            columns in the partition key if the table is partitioned. Note that a
              <codeph>&lt;key&gt;</codeph> constraint in a partitioned table is not the same as a
            simple <codeph>UNIQUE INDEX</codeph>.</pd>
          <pd>For information about unique constraint management and limitations, see <xref
              href="#topic1/section5" format="dita"/>.</pd>
        </plentry>
        <plentry>
          <pt>PRIMARY KEY ( <varname>column constraint</varname> )</pt>
          <pt>PRIMARY KEY ( <varname>column_name</varname> [, ... ] ) ( <varname>table
              constraint</varname> )</pt>
          <pd>The <codeph>PRIMARY KEY</codeph> constraint specifies that a column or columns of a
            table may contain only unique (non-duplicate), non-null values. Only one primary key can
            be specified for a table, whether as a column constraint or a table constraint. </pd>
          <pd>For a table to have a primary key, it must be hash distributed (not randomly
            distributed), and the primary key, the column(s) that are unique, must contain all the
            columns of the Greenplum distribution key. In addition, the <codeph>&lt;key&gt;</codeph>
            must contain all the columns in the partition key if the table is partitioned. Note that
            a <codeph>&lt;key&gt;</codeph> constraint in a partitioned table is not the same as a
            simple <codeph>UNIQUE INDEX</codeph>. </pd>
          <pd><codeph>PRIMARY KEY</codeph> enforces the same data constraints as a combination of
              <codeph>UNIQUE</codeph> and <codeph>NOT NULL</codeph>, but identifying a set of
            columns as the primary key also provides metadata about the design of the schema, since
            a primary key implies that other tables can rely on this set of columns as a unique
            identifier for rows. </pd>
          <pd>For information about primary key management and limitations, see <xref
              href="#topic1/section5" format="dita"/>. </pd>
        </plentry>
        <plentry>
          <pt>REFERENCES <varname>reftable</varname> [ ( <varname>refcolumn</varname> ) ] </pt>
          <pt>     [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]</pt>
          <pt>     [ON DELETE | ON UPDATE]  [<varname>key_action</varname>]</pt>
          <pt>FOREIGN KEY (<varname>column_name</varname> [, ...])</pt>
          <pd>The <codeph>REFERENCES</codeph> and <codeph>FOREIGN KEY</codeph> clauses specify
            referential integrity constraints (foreign key constraints). Greenplum accepts
            referential integrity constraints as specified in PostgreSQL syntax but does not enforce
            them. See the PostgreSQL documentation for information about referential integrity
            constraints.</pd>
        </plentry>
        <plentry>
          <pt>DEFERRABLE</pt>
          <pt>NOT DEFERRABLE</pt>
          <pd>The <codeph>[NOT] DEFERRABLE</codeph> clause controls whether the constraint can be
            deferred. A constraint that is not deferrable will be checked immediately after every
            command. Checking of constraints that are deferrable can be postponed until the end of
            the transaction (using the <xref href="SET_CONSTRAINTS.xml#topic1"><codeph>SET
                CONSTRAINTS</codeph></xref> command). <codeph>NOT DEFERRABLE</codeph> is the
            default. Currently, only <codeph>UNIQUE</codeph> and <codeph>PRIMARY KEY</codeph>
            constraints are deferrable.  <codeph>NOT NULL</codeph> and <codeph>CHECK</codeph>
            constraints are not deferrable. <codeph>REFERENCES</codeph> (foreign key) constraints
            accept this clause but are not enforced. </pd>
        </plentry>
        <plentry><pt>INITIALLY IMMEDIATE</pt>
        <pt>INITIALLY DEFERRED</pt>
          <pd>If a constraint is deferrable, this clause specifies the default time to check the
            constraint. If the constraint is <codeph>INITIALLY IMMEDIATE</codeph>, it is checked
            after each statement. This is the default. If the constraint is <codeph>INITIALLY
              DEFERRED</codeph>, it is checked only at the end of the transaction. The constraint
            check time can be altered with the <codeph>SET CONSTRAINTS</codeph> command. </pd></plentry>
        <plentry id="with_storage">
          <pt>WITH ( <varname>storage_parameter=value</varname> ) </pt>
          <pd>The <codeph>WITH</codeph> clause can specify storage parameters for tables, and for
            indexes associated with a <codeph>UNIQUE</codeph> or <codeph>PRIMARY</codeph>
            constraint. Note that you can also set storage parameters on a particular partition or
            subpartition by declaring the <codeph>WITH</codeph> clause in the partition
            specification. The lowest-level settings have priority.</pd>
          <pd>The defaults for some of the table storage options can be specified with the server
            configuration parameter <codeph>gp_default_storage_options</codeph>. For information
            about setting default storage options, see <xref href="#topic1/section5" format="dita"
            />. </pd>
          <pd>The following storage options are available:</pd>
          <pd><b>appendoptimized</b> — Set to <codeph>TRUE</codeph> to create the table as an
            append-optimized table. If <codeph>FALSE</codeph> or not declared, the table will be
            created as a regular heap-storage table.</pd>
          <pd><b>blocksize</b> — Set to the size, in bytes, for each block in a table. The
              <codeph>blocksize</codeph> must be between 8192 and 2097152 bytes, and be a multiple
            of 8192. The default is 32768. The <codeph>blocksize</codeph>
            option is valid only if <codeph>appendoptimized=TRUE</codeph>.</pd>
          <pd><b>orientation</b> — Set to <codeph>column</codeph> for column-oriented storage, or
              <codeph>row</codeph> (the default) for row-oriented storage. This option is only valid
            if <codeph>appendoptimized=TRUE</codeph>. Heap-storage tables can only be row-oriented.</pd>
          <pd><b>checksum</b> — This option is valid only for append-optimized tables
              (<codeph>appendoptimized=TRUE</codeph>). The value <codeph>TRUE</codeph> is the
            default and enables CRC checksum validation for append-optimized tables. The checksum is
            calculated during block creation and is stored on disk. Checksum validation is performed
            during block reads. If the checksum calculated during the read does not match the stored
            checksum, the transaction is cancelled. If you set the value to
              <codeph>FALSE</codeph> to disable checksum validation, checking the table data for
            on-disk corruption will not be performed.</pd>
          <pd><b>compresstype</b> — Set to <codeph>ZLIB</codeph> (the default),
              <codeph>ZSTD</codeph>, <codeph>RLE_TYPE</codeph>, or
              <codeph>QUICKLZ</codeph><sup>1</sup> to specify the type of compression used. The
            value <codeph>NONE</codeph> disables compression. Zstd provides for both speed or a good
            compression ratio, tunable with the <codeph>compresslevel</codeph> option. QuickLZ and
            zlib are provided for backwards-compatibility. Zstd outperforms these compression types
            on usual workloads. The <codeph>compresstype</codeph> option is only valid if
              <codeph>appendoptimized=TRUE</codeph>.<p>
              <note type="note"><sup>1</sup>QuickLZ compression is available only in the commercial
                release of Tanzu Greenplum.</note>
            </p><p>The value <codeph>RLE_TYPE</codeph>, which is supported only if
                <codeph>orientation</codeph>=<codeph>column</codeph> is specified, enables the
              run-length encoding (RLE) compression algorithm. RLE compresses data better than the
              Zstd, zlib, or QuickLZ compression algorithms when the same data value occurs in many
              consecutive rows.</p><p>For columns of type <codeph>BIGINT</codeph>,
                <codeph>INTEGER</codeph>, <codeph>DATE</codeph>, <codeph>TIME</codeph>, or
                <codeph>TIMESTAMP</codeph>, delta compression is also applied if the
                <codeph>compresstype</codeph> option is set to <codeph>RLE_TYPE</codeph>
              compression. The delta compression algorithm is based on the delta between column
              values in consecutive rows and is designed to improve compression when data is loaded
              in sorted order or the compression is applied to column data that is in sorted
              order.</p><p>For information about using table compression, see
              <xref href="../../admin_guide/ddl/ddl-storage.html#topic1" scope="external"
                format="html">Choosing the Table Storage Model</xref>
              in the <cite>Greenplum Database Administrator Guide</cite>.</p></pd>
              <pd><b>compresslevel</b> — For Zstd compression of append-optimized tables, set to an
            integer value from 1 (fastest compression) to 19 (highest compression ratio). For zlib
            compression, the valid range is from 1 to 9. QuickLZ compression level can only be set
            to 1. If not declared, the default is 1. For <codeph>RLE_TYPE</codeph>, the compression
            level can be an integer value from 1 (fastest compression) to 4 (highest compression
            ratio). </pd>
          <pd>The <codeph>compresslevel</codeph> option is valid only if <codeph>appendoptimized=TRUE</codeph>.</pd>
          <pd><b>fillfactor</b> — The fillfactor for a table is a percentage between 10 and 100.
            100 (complete packing) is the default. When a smaller fillfactor is specified,
            <codeph>INSERT</codeph> operations pack table pages only to the indicated percentage;
            the remaining space on each page is reserved for updating rows on that page. This
             gives <codeph>UPDATE</codeph> a chance to place the updated copy of a row on the
             same page as the original, which is more efficient than placing it on a different
             page. For a table whose entries are never updated, complete packing is the best
             choice, but in heavily updated tables smaller fillfactors are appropriate. This
             parameter cannot be set for TOAST tables.</pd>
          <pd><b>oids=FALSE</b> — This setting is the default, and it ensures that rows do not have
            object identifiers assigned to them. <ph otherprops="pivotal">VMware does not support
              using <codeph>WITH OIDS</codeph> or <codeph>oids=TRUE</codeph> to assign an OID system
              column. </ph>On large tables, such as those in a typical Greenplum Database system,
            using OIDs for table rows can cause wrap-around of the 32-bit OID counter. Once the
            counter wraps around, OIDs can no longer be assumed to be unique, which not only makes
            them useless to user applications, but can also cause problems in the Greenplum Database
            system catalog tables. In addition, excluding OIDs from a table reduces the space
            required to store the table on disk by 4 bytes per row, slightly improving performance.
            You cannot create OIDS on a partitioned or column-oriented table (an error is
            displayed). This syntax is deprecated and will be removed in a future Greenplum
            release.</pd>
        </plentry>
        <plentry>
          <pt>ON COMMIT</pt>
          <pd>The behavior of temporary tables at the end of a transaction block can be controlled
            using <codeph>ON COMMIT</codeph>. The three options are: </pd>
          <pd><b>PRESERVE ROWS</b> - No special action is taken at the ends of transactions for
            temporary tables. This is the default behavior. </pd>
          <pd><b>DELETE ROWS</b> - All rows in the temporary table will be deleted at the end of
            each transaction block. Essentially, an automatic <codeph>TRUNCATE</codeph> is done at
            each commit. </pd>
          <pd><b>DROP</b> - The temporary table will be dropped at the end of the current
            transaction block. </pd>
        </plentry>
        <plentry>
          <pt>TABLESPACE <varname>tablespace</varname></pt>
          <pd>The name of the tablespace in which the new table is to be created. If not specified,
            the database's default tablespace is used, or <xref
              href="../config_params/guc-list.xml#topic_k52_fqm_f3b"/> if the table is
            temporary.</pd>
        </plentry>
        <plentry>
          <pt>USING INDEX TABLESPACE <varname>tablespace</varname></pt>
          <pd>This clause allows selection of the tablespace in which the index associated with a
              <codeph>UNIQUE</codeph> or <codeph>PRIMARY KEY</codeph> constraint will be created. If
            not specified, the database's default tablespace is used, or <xref
              href="../config_params/guc-list.xml#topic_k52_fqm_f3b"/> if the table is temporary. </pd>
        </plentry>
        <plentry>
          <pt>DISTRIBUTED BY (<varname>column</varname> [<varname>opclass</varname>], [ ... ] )</pt>
          <pt>DISTRIBUTED RANDOMLY</pt>
          <pt>DISTRIBUTED REPLICATED</pt>
          <pd>Used to declare the Greenplum Database distribution policy for the table.
              <codeph>DISTRIBUTED BY</codeph> uses hash distribution with one or more columns
            declared as the distribution key. For the most even data distribution, the distribution
            key should be the primary key of the table or a unique column (or set of columns). If
            that is not possible, then you may choose <codeph>DISTRIBUTED RANDOMLY</codeph>, which
            will send the data round-robin to the segment instances. Additionally, an operator
            class, <codeph>opclass</codeph>, can be specified, to use a non-default hash function. </pd>
          <pd>The Greenplum Database server configuration parameter
              <codeph>gp_create_table_random_default_distribution</codeph> controls the default
            table distribution policy if the <cmdname>DISTRIBUTED BY</cmdname> clause is not
            specified when you create a table. Greenplum Database follows these rules to create a
            table if a distribution policy is not specified. <p>If the value of the parameter is
                <codeph>off</codeph> (the default), Greenplum Database chooses the table
              distribution key based on the command:<ul id="ul_rjb_gty_qfb">
                <li>If a <codeph>LIKE</codeph> or <codeph>INHERITS</codeph> clause is specified,
                  then Greenplum copies the distribution key from the source or parent table.</li>
                <li>If a <codeph>PRIMARY KEY</codeph> or <codeph>UNIQUE</codeph> constraints are
                  specified, then Greenplum chooses the largest subset of all the key columns as the
                  distribution key.</li>
                <li>If neither constraints nor a <codeph>LIKE</codeph> or <codeph>INHERITS</codeph>
                  clause is specified, then Greenplum chooses the first suitable column as the
                  distribution key. (Columns with geometric or user-defined data types are not
                  eligible as Greenplum distribution key columns.)</li>
              </ul></p><p>If the value of the parameter is set to <codeph>on</codeph>, Greenplum
              Database follows these rules:<ul id="ul_tbr_5kq_kq">
                <li>If <cmdname>PRIMARY KEY</cmdname> or <cmdname>UNIQUE</cmdname> columns are not
                  specified, the distribution of the table is random (<cmdname>DISTRIBUTED
                    RANDOMLY</cmdname>). Table distribution is random even if the table creation
                  command contains the <cmdname>LIKE</cmdname> or <cmdname>INHERITS</cmdname>
                  clause. </li>
                <li>If <cmdname>PRIMARY KEY</cmdname> or <cmdname>UNIQUE</cmdname> columns are
                  specified, a <cmdname>DISTRIBUTED BY</cmdname> clause must also be specified. If a
                    <cmdname>DISTRIBUTED BY</cmdname> clause is not specified as part of the table
                  creation command, the command fails.</li>
              </ul></p></pd>
          <pd>For more information about setting the default table distribution policy, see <xref
              href="../config_params/guc-list.xml#gp_create_table_random_default_distribution"
              type="section" format="dita"
                ><codeph>gp_create_table_random_default_distribution</codeph></xref>. </pd>
          <pd>The <codeph>DISTRIBUTED REPLICATED</codeph> clause replicates the entire table to all
            Greenplum Database segment instances. It can be used when it is necessary to run 
            user-defined functions on segments when the functions require access to all rows in the
            table, or to improve query performance by preventing broadcast motions. </pd>
        </plentry>
        <plentry id="part_by">
          <pt>PARTITION BY</pt>
          <pd>Declares one or more columns by which to partition the table.</pd>
          <pd>When creating a partitioned table, Greenplum Database creates the root partitioned
            table (the root partition) with the specified table name. Greenplum Database also
            creates a hierarchy of tables, child tables, that are the subpartitions based on the
            partitioning options that you specify. The Greenplum Database <i>pg_partition</i>*
            system views contain information about the subpartition tables.</pd>
          <pd>For each partition level (each hierarchy level of tables), a partitioned table can
            have a maximum of 32,767 partitions. </pd>
          <pd>
            <note> Greenplum Database stores partitioned table data in the leaf child tables, the
              lowest-level tables in the hierarchy of child tables for use by the partitioned
              table.</note>
          </pd>
          <pd>
            <parml>
              <plentry>
                <pt>
                  <varname>partition_type</varname>
                </pt>
                <pd>Declares partition type: <codeph>LIST</codeph> (list of values) or
                    <codeph>RANGE</codeph> (a numeric or date range). </pd>
              </plentry>
              <plentry>
                <pt>
                  <varname>partition_specification</varname>
                </pt>
                <pd>Declares the individual partitions to create. Each partition can be defined
                  individually or, for range partitions, you can use the <codeph>EVERY</codeph>
                  clause (with a <codeph>START</codeph> and optional <codeph>END</codeph> clause) to
                  define an increment pattern to use to create the individual partitions.</pd>
                <pd><b><codeph>DEFAULT PARTITION <varname>name</varname></codeph></b> — Declares a
                  default partition. When data does not match to an existing partition, it is
                  inserted into the default partition. Partition designs that do not have a default
                  partition will reject incoming rows that do not match to an existing
                  partition.</pd>
                <pd><b><codeph>PARTITION <varname>name</varname></codeph></b> — Declares a name to
                  use for the partition. Partitions are created using the following naming
                  convention:
                      <codeph><varname>parentname</varname>_<varname>level#</varname>_prt_<varname>givenname</varname></codeph>.</pd>
                <pd><b><codeph>VALUES</codeph></b> — For list partitions, defines the value(s) that
                  the partition will contain.</pd>
                <pd><b><codeph>START</codeph></b> — For range partitions, defines the starting range
                  value for the partition. By default, start values are <codeph>INCLUSIVE</codeph>.
                  For example, if you declared a start date of '<codeph>2016-01-01</codeph>', then
                  the partition would contain all dates greater than or equal to
                    '<codeph>2016-01-01</codeph>'. Typically the data type of the
                    <codeph>START</codeph> expression is the same type as the partition key column.
                  If that is not the case, then you must explicitly cast to the intended data type. </pd>
                <pd><b><codeph>END</codeph></b> — For range partitions, defines the ending range
                  value for the partition. By default, end values are <codeph>EXCLUSIVE</codeph>.
                  For example, if you declared an end date of '<codeph>2016-02-01</codeph>', then
                  the partition would contain all dates less than but not equal to
                    '<codeph>2016-02-01</codeph>'. Typically the data type of the
                    <codeph>END</codeph> expression is the same type as the partition key column. If
                  that is not the case, then you must explicitly cast to the intended data
                  type.</pd>
                <pd><b><codeph>EVERY</codeph></b> — For range partitions, defines how to increment
                  the values from <codeph>START</codeph> to <codeph>END</codeph> to create
                  individual partitions. Typically the data type of the <codeph>EVERY</codeph>
                  expression is the same type as the partition key column. If that is not the case,
                  then you must explicitly cast to the intended data type.</pd>
                <pd><b><codeph>WITH</codeph>
                  </b>— Sets the table storage options for a partition. For example, you may want
                  older partitions to be append-optimized tables and newer partitions to be regular
                  heap tables. </pd>
                <pd><b><codeph>TABLESPACE</codeph></b> — The name of the tablespace in which the
                  partition is to be created. </pd>
              </plentry>
            </parml>
          </pd>
        </plentry>
        <plentry>
          <pt>SUBPARTITION BY</pt>
          <pd>Declares one or more columns by which to subpartition the first-level partitions of
            the table. The format of the subpartition specification is similar to that of a
            partition specification described above. </pd>
        </plentry>
        <plentry>
          <pt>SUBPARTITION TEMPLATE</pt>
          <pd>Instead of declaring each subpartition definition individually for each partition, you
            can optionally declare a subpartition template to be used to create the subpartitions
            (lower level child tables). This subpartition specification would then apply to all
            parent partitions.</pd>
        </plentry>
      </parml>
    </section>
    <section id="section5">
      <title>Notes</title>
      <ul id="ul_stf_sl1_tt">
        <li>In Greenplum Database (a Postgres-based system) the data types <codeph>VARCHAR</codeph>
          or <codeph>TEXT</codeph> handle padding added to the textual data (space characters added
          after the last non-space character) as significant characters; the data type
            <codeph>CHAR</codeph> does not.<p>In Greenplum Database, values of type
                <codeph>CHAR(<varname>n</varname>)</codeph> are padded with trailing spaces to the
            specified width <varname>n</varname>. The values are stored and displayed with the
            spaces. However, the padding spaces are treated as semantically insignificant. When the
            values are distributed, the trailing spaces are disregarded. The trailing spaces are
            also treated as semantically insignificant when comparing two values of data type
              <codeph>CHAR</codeph>, and the trailing spaces are removed when converting a character
            value to one of the other string types. </p></li>
        <li><ph otherprops="pivotal">VMware does not support using <codeph>WITH OIDS</codeph> or
              <codeph>oids=TRUE</codeph> to assign an OID system column. </ph><ph
            otherprops="oss-only">Using OIDs in new applications is not recommended. </ph> This
          syntax is deprecated and will be removed in a future Greenplum release. As an alternative,
          use a <codeph>SERIAL</codeph> or other sequence generator as the table's primary key.
          However, if your application does make use of OIDs to identify specific rows of a table,
          it is recommended to create a unique constraint on the OID column of that table, to ensure
          that OIDs in the table will indeed uniquely identify rows even after counter wrap-around.
          Avoid assuming that OIDs are unique across tables; if you need a database-wide unique
          identifier, use the combination of table OID and row OID for that purpose.</li>
        <li>Greenplum Database has some special conditions for primary key and unique constraints
          with regards to columns that are the <i>distribution key</i> in a Greenplum table. For a
          unique constraint to be enforced in Greenplum Database, the table must be hash-distributed
          (not <codeph>DISTRIBUTED RANDOMLY</codeph>), and the constraint columns must be the same
          as (or a superset of) the table's distribution key columns. <p>Replicated tables
              (<codeph>DISTRIBUTED REPLICATED</codeph>) can have both <codeph>PRIMARY KEY</codeph>
            and <codeph>UNIQUE</codeph>column constraints.</p><p>A primary key constraint is simply
            a combination of a unique constraint and a not-null constraint.</p><p>Greenplum Database
            automatically creates a <codeph>UNIQUE</codeph> index for each <codeph>UNIQUE</codeph>
            or <codeph>PRIMARY KEY</codeph> constraint to enforce uniqueness. Thus, it is not
            necessary to create an index explicitly for primary key columns. <codeph>UNIQUE</codeph>
            and <codeph>PRIMARY KEY</codeph> constraints are not allowed on append-optimized tables
            because the <codeph>UNIQUE</codeph> indexes that are created by the constraints are not
            allowed on append-optimized tables.</p><p>Foreign key constraints are not supported in
            Greenplum Database. </p><p>For inherited tables, unique constraints, primary key
            constraints, indexes and table privileges are <i>not</i> inherited in the current
            implementation.</p></li>
        <li>For append-optimized tables, <codeph>UPDATE</codeph> and <codeph>DELETE</codeph> are not
          allowed in a repeatable read or serializable transaction and will cause the transaction to
          end prematurely. <codeph>DECLARE...FOR UPDATE</codeph>, and triggers are not supported
          with append-optimized tables. <codeph>CLUSTER</codeph> on append-optimized tables is only
          supported over B-tree indexes.</li>
        <li>To insert data into a partitioned table, you specify the root partitioned table, the
          table created with the <codeph>CREATE TABLE</codeph> command. You also can specify a leaf
          child table of the partitioned table in an <codeph>INSERT</codeph> command. An error is
          returned if the data is not valid for the specified leaf child table. Specifying a child
          table that is not a leaf child table in the <codeph>INSERT</codeph> command is not
          supported. Execution of other DML commands such as <codeph>UPDATE</codeph> and
            <codeph>DELETE</codeph> on any child table of a partitioned table is not supported.
          These commands must be run on the root partitioned table, the table created with the
            <codeph>CREATE TABLE</codeph> command.</li>
        <li>The default values for these table storage options can be specified with the server
          configuration parameter <codeph>gp_default_storage_option</codeph>.<ul id="ul_hr1_3m1_tt">
            <li>
              <cmdname>appendoptimized</cmdname>
            </li>
            <li>
              <cmdname>blocksize</cmdname>
            </li>
            <li>
              <cmdname>checksum</cmdname>
            </li>
            <li>
              <cmdname>compresstype</cmdname>
            </li>
            <li>
              <cmdname>compresslevel</cmdname>
            </li>
            <li>
              <cmdname>orientation</cmdname>
            </li>
          </ul><p>The defaults can be set for the system, a database, or a user. For information
            about setting storage options, see the server configuration parameter <codeph><xref
                href="../../ref_guide/config_params/guc-list.xml#gp_default_storage_options"
                >gp_default_storage_options</xref></codeph>.</p></li>
      </ul>
      <note type="important">The current Postgres Planner allows list partitions
        with multi-column (composite) partition keys. GPORCA does not support composite keys, so
        using composite partition keys is not recommended.</note>
    </section>
    <section id="section6">
      <title>Examples</title>
      <p>Create a table named <codeph>rank</codeph> in the schema named <codeph>baby</codeph> and
        distribute the data using the columns <codeph>rank</codeph>, <codeph>gender</codeph>, and
          <codeph>year</codeph>:</p>
      <codeblock>CREATE TABLE baby.rank (id int, rank int, year smallint, 
gender char(1), count int ) DISTRIBUTED BY (rank, gender, 
year);</codeblock>
      <p>Create table films and table distributors (the primary key will be used as the Greenplum
        distribution key by default): </p>
      <codeblock>CREATE TABLE films (
code        char(5) CONSTRAINT firstkey PRIMARY KEY,
title       varchar(40) NOT NULL,
did         integer NOT NULL,
date_prod   date,
kind        varchar(10),
len         interval hour to minute
);

CREATE TABLE distributors (
did    integer PRIMARY KEY DEFAULT nextval('serial'),
name   varchar(40) NOT NULL CHECK (name &lt;&gt; '')
);</codeblock>
      <p>Create a gzip-compressed, append-optimized table:</p>
      <codeblock>CREATE TABLE sales (txn_id int, qty int, date date) 
WITH (appendoptimized=true, compresslevel=5) 
DISTRIBUTED BY (txn_id);</codeblock>
      <p>Create a simple, single level partitioned
        table:<codeblock>CREATE TABLE sales (id int, year int, qtr int, c_rank int, code char(1), region text)
DISTRIBUTED BY (id)
PARTITION BY LIST (code)
( PARTITION sales VALUES ('S'),
  PARTITION returns VALUES ('R')
);</codeblock></p>
      <p>Create a three level partitioned table that defines subpartitions without the
          <codeph>SUBPARTITION TEMPLATE</codeph> clause:
        <codeblock>CREATE TABLE sales (id int, year int, qtr int, c_rank int, code char(1), region text)
DISTRIBUTED BY (id)
PARTITION BY LIST (code)
  SUBPARTITION BY RANGE (c_rank)
    SUBPARTITION by LIST (region)

( PARTITION sales VALUES ('S')
   ( SUBPARTITION cr1 START (1) END (2)
      ( SUBPARTITION ca VALUES ('CA') ), 
      SUBPARTITION cr2 START (3) END (4)
        ( SUBPARTITION ca VALUES ('CA') ) ),

 PARTITION returns VALUES ('R')
   ( SUBPARTITION cr1 START (1) END (2)
      ( SUBPARTITION ca VALUES ('CA') ), 
     SUBPARTITION cr2 START (3) END (4)
        ( SUBPARTITION ca VALUES ('CA') ) )
);</codeblock></p>
      <p>Create the same partitioned table as the previous table using the <codeph>SUBPARTITION
          TEMPLATE</codeph>
        clause:<codeblock>CREATE TABLE sales1 (id int, year int, qtr int, c_rank int, code char(1), region text)
DISTRIBUTED BY (id)
PARTITION BY LIST (code)

   SUBPARTITION BY RANGE (c_rank)
     SUBPARTITION TEMPLATE (
     SUBPARTITION cr1 START (1) END (2),
     SUBPARTITION cr2 START (3) END (4) )

     SUBPARTITION BY LIST (region)
       SUBPARTITION TEMPLATE (
       SUBPARTITION ca VALUES ('CA') )

( PARTITION sales VALUES ('S'),
  PARTITION  returns VALUES ('R')
) ;</codeblock></p>
      <p>Create a three level partitioned table using subpartition templates and default partitions
        at each
        level:<codeblock>CREATE TABLE sales (id int, year int, qtr int, c_rank int, code char(1), region text)
DISTRIBUTED BY (id)
PARTITION BY RANGE (year)

  SUBPARTITION BY RANGE (qtr)
    SUBPARTITION TEMPLATE (
    START (1) END (5) EVERY (1), 
    DEFAULT SUBPARTITION bad_qtr )

    SUBPARTITION BY LIST (region)
      SUBPARTITION TEMPLATE (
      SUBPARTITION usa VALUES ('usa'),
      SUBPARTITION europe VALUES ('europe'),
      SUBPARTITION asia VALUES ('asia'),
      DEFAULT SUBPARTITION other_regions)

( START (2009) END (2011) EVERY (1),
  DEFAULT PARTITION outlying_years);</codeblock></p>
    </section>
    <section id="section7">
      <title>Compatibility</title>
      <p><codeph>CREATE TABLE</codeph> command conforms to the SQL standard, with the following
        exceptions:</p>
      <ul>
        <li id="cd150267"><b>Temporary Tables</b> — In the SQL standard, temporary tables are
          defined just once and automatically exist (starting with empty contents) in every session
          that needs them. Greenplum Database instead requires each session to issue its own
            <codeph>CREATE TEMPORARY TABLE</codeph> command for each temporary table to be used.
          This allows different sessions to use the same temporary table name for different
          purposes, whereas the standard's approach constrains all instances of a given temporary
          table name to have the same table structure. <p>The standard's distinction between global
            and local temporary tables is not in Greenplum Database. Greenplum Database will accept
            the <codeph>GLOBAL</codeph> and <codeph>LOCAL</codeph> keywords in a temporary table
            declaration, but they have no effect and are deprecated.</p><p>If the <codeph>ON
              COMMIT</codeph> clause is omitted, the SQL standard specifies that the default
            behavior as <codeph>ON COMMIT DELETE ROWS</codeph>. However, the default behavior in
            Greenplum Database is <codeph>ON COMMIT PRESERVE ROWS</codeph>. The <codeph>ON COMMIT
              DROP</codeph> option does not exist in the SQL standard. </p></li>
        <li id="cd150376"><b>Column Check Constraints</b> — The SQL standard says that
            <codeph>CHECK</codeph> column constraints may only refer to the column they apply to;
          only <codeph>CHECK</codeph> table constraints may refer to multiple columns. Greenplum
          Database does not enforce this restriction; it treats column and table check constraints
          alike. </li>
        <li id="cd150386"><b>NULL Constraint</b> — The <codeph>NULL</codeph> constraint is a
          Greenplum Database extension to the SQL standard that is included for compatibility with
          some other database systems (and for symmetry with the <codeph>NOT NULL</codeph>
          constraint). Since it is the default for any column, its presence is not required.</li>
        <li id="cd150401"><b>Inheritance</b> — Multiple inheritance via the
            <codeph>INHERITS</codeph> clause is a Greenplum Database language extension. SQL:1999
          and later define single inheritance using a different syntax and different semantics.
          SQL:1999-style inheritance is not yet supported by Greenplum Database. </li>
        <li id="cd153512"><b>Partitioning</b> — Table partitioning via the <codeph>PARTITION
            BY</codeph> clause is a Greenplum Database language extension. </li>
        <li id="cd150414"><b>Zero-column tables</b> — Greenplum Database allows a table of no
          columns to be created (for example, <codeph>CREATE TABLE foo();</codeph>). This is an
          extension from the SQL standard, which does not allow zero-column tables. Zero-column
          tables are not in themselves very useful, but disallowing them creates odd special cases
          for <codeph>ALTER TABLE DROP COLUMN</codeph>, so Greenplum decided to ignore this spec
          restriction. </li>
        <li><b>LIKE</b> — While a <codeph>LIKE</codeph> clause exists in the SQL standard, many of the
          options that Greenplum Database accepts for it are not
          in the standard, and some of the standard's options are not implemented
          by Greenplum Database.</li>
        <li id="cd150435"><b>WITH clause</b> — The <codeph>WITH</codeph> clause is a Greenplum
          Database extension; neither storage parameters nor OIDs are in the standard. </li>
        <li id="cd150445"><b>Tablespaces</b> — The Greenplum Database concept of tablespaces is not
          part of the SQL standard. The clauses <codeph>TABLESPACE</codeph> and <codeph>USING INDEX
            TABLESPACE</codeph> are extensions. </li>
        <li id="cd150459"><b>Data Distribution</b> — The Greenplum Database concept of a parallel or
          distributed database is not part of the SQL standard. The <codeph>DISTRIBUTED</codeph>
          clauses are extensions.</li>
      </ul>
    </section>
    <section id="section8">
      <title>See Also</title>
      <p><codeph><xref href="ALTER_TABLE.xml#topic1" type="topic" format="dita">ALTER
          TABLE</xref></codeph>, <codeph><xref href="./DROP_TABLE.xml#topic1" type="topic"
            format="dita">DROP TABLE</xref></codeph>, <codeph><xref
            href="CREATE_EXTERNAL_TABLE.xml#topic1" type="topic" format="dita">CREATE EXTERNAL
            TABLE</xref></codeph>, <codeph><xref href="./CREATE_TABLE_AS.xml#topic1" type="topic"
            format="dita">CREATE TABLE AS</xref></codeph></p>
    </section>
  </body>
</topic>
